<template>
	<view :class="[BackGround]" :style="[{'font-weight':Style,'font-family':Font,height:100 + '%',minHeight:height + 'px'}]">
		<cu-custom bgColor="bg-gradual-blue" isBack="true">
			<view slot="backText">返回</view>
			<view slot="content">访客记录</view>
		</cu-custom>
		<sear-ch :placeholder="placeholder" @clean="clean" @input="input" @remove="remove" :message="message"></sear-ch>
		<screen-view ref="screen" @formSubmit="formSubmit" :searchCondition="searchCondition" :isShow="false" :startbefore="dateleft"></screen-view>
		<mix-pulldown-refresh ref="mixPulldownRefresh" :top="CustomBar + 100" :scrolltopa="scrollTop" @refresh="onPulldownReresh"
		 @setEnableScroll="setEnableScroll" @scroll='scroll'>
			<z-table :tableData="deliverplantwo" :stickSide="false" :showSelect="false" :showBottomSum="false" :columns="finaleColumnstwo"
			 @onSort="doSort" @onSelect="tableSelect" :num="0" :bottom="180"></z-table>
			<!-- 上滑加载更多组件 -->
			<mix-load-more :status="2" v-if="!isFlag"></mix-load-more>
		</mix-pulldown-refresh>
		<!-- #ifdef APP-PLUS -->
		<view class="table-fixed" @tap="switchP">
			<image :class="[imgclass]" src="/static/images/phoneicon.png" mode="aspectFill"></image>
		</view>
		<!-- #endif -->
		<button class="cu-btn bg-gradual-blue lg shadow tb-flex cu-btn-new fixed_Export" @tap="Export">导出</button>
	</view>
</template>

<script>
	import SearCh from "@/colorui/components/search.nvue";
	import ScreenView from '@/colorui/components/ScreenView.vue'
	import zTable from "@/colorui/components/z-table.vue";
	import utils from '@/static/js/utils.filter.js';
	import mixPulldownRefresh from '@/colorui/components/mixpulldownrefresh.vue'
	import mixLoadMore from '@/colorui/components/mixloadmore';
	import {
		mapGetters
	} from "vuex";
	import {
		inputSearch,
		viewTable,
		tableFixed,
		scrollrefresh
	} from "@/mixin/mixin.js"
	import {
		OA
	} from "@/service/selectList.js"
	import {
		generateExcel
	} from "@/service/insert.js"
	export default {
		mixins: [viewTable, inputSearch, tableFixed,scrollrefresh],
		data() {
			return {
				placeholder: "机器",
				height: this.screenHeight,
				message: '筛选',
				isFlag: false,
				dateleft: global.startbefore,
				dateright: global.dateright,
				searchView: "LATEMACHINE",
				searchCondition: [{
					name: '机器',
					code: 'LATEMACHINE',
					checked: true
				}, ],
				// picker: [{
				// 		LNAME: "V1"
				// 	},
				// 	{
				// 		LNAME: "V2"
				// 	}
				// ],
			}
		},
		computed: {
			...mapGetters(["Style", 'Font', 'BackGround', 'BackGroundBox'])
		},
		components: {
			SearCh,
			ScreenView,
			zTable,
			mixPulldownRefresh,
			mixLoadMore
		},
		onUnload() {
			// console.log('销毁');
			// plus.screen.unlockOrientation();
			// plus.screen.lockOrientation('portrait-primary');
		},
		onLoad() {
			function getNextDay(d) {
				d = new Date(d);
				d = +d + 1000 * 60 * 60 * 24;
				d = new Date(d);
				//return d;
				//格式化
				let y = d.getMonth() + 1
				let t = d.getDate()
				return d.getFullYear() + "-" + (y < 10 ? '0' + y : y) + '-' + (t < 10 ? '0' + t : t)
			}
			this.dateright = getNextDay(this.dateright)
			this.getOA()
		},
		methods: {
			onPulldownReresh() {
				this.getOA()
			},
			getOA() {
				OA('授权访客', this.dateleft, this.dateright).then(res => {
					for (let item of res.data) {
						item['isShow'] = true
						var thisTime = item.LATEDATE.replace("T", " ").substring(0, 19).replace(/-/g, '/');
						var thisTime2 = item.LALLOWBEGINDATE.replace("T", " ").substring(0, 19).replace(/-/g, '/');
						var thisTime3 = item.LALLOWENDDATE.replace("T", " ").substring(0, 19).replace(/-/g, '/');
						item.LATEDATE = utils.timeTodate('Y-m-d H:i:s', new Date(thisTime).getTime() + 8 * 3600 * 1000)
						item.LALLOWBEGINDATE = utils.timeTodate('Y-m-d H:i:s', new Date(thisTime2).getTime() + 8 * 3600 * 1000)
						item.LALLOWENDDATE = utils.timeTodate('Y-m-d H:i:s', new Date(thisTime3).getTime() + 8 * 3600 * 1000)
					}
					setTimeout(() => {
						this.$refs.mixPulldownRefresh.endPulldownRefresh()
					},500)
					this.deliverplantwo = res.data
					this.deliverplan = res.data
				})
			},
			formSubmit(e) {
				this.dateleft = e.picker1
				this.dateright = e.picker2
				OA('授权访客', this.dateleft, this.dateright).then(res => {
					for (let item of res.data) {
						item['isShow'] = true
						var thisTime = item.LATEDATE.replace("T", " ").substring(0, 19).replace(/-/g, '/');
						var thisTime2 = item.LALLOWBEGINDATE.replace("T", " ").substring(0, 19).replace(/-/g, '/');
						var thisTime3 = item.LALLOWENDDATE.replace("T", " ").substring(0, 19).replace(/-/g, '/');
						item.LATEDATE = utils.timeTodate('Y-m-d H:i:s', new Date(thisTime).getTime() + 8 * 3600 * 1000)
						item.LALLOWBEGINDATE = utils.timeTodate('Y-m-d H:i:s', new Date(thisTime2).getTime() + 8 * 3600 * 1000)
						item.LALLOWENDDATE = utils.timeTodate('Y-m-d H:i:s', new Date(thisTime3).getTime() + 8 * 3600 * 1000)
					}
					this.deliverplantwo = res.data
					this.deliverplan = res.data

				})
			},
			Export() {
				if(this.deliverplantwo.length > 0) {
					let mylist = []
					this.deliverplantwo.forEach((value,index) => {
						if(value['isShow'] == true) {
							mylist.push(value)
						}
					})
					generateExcel('FKExcelPojo',mylist).then(res => {
						if(res.code == 1) {
							plus.runtime.openURL(`http://60.173.239.156:8443/image/UserImage/${res.data}`);
						} else {
							uni.showToast({
								title:'导出失败',
								icon:'none'
							})
						}
					})
				} else {
					uni.showToast({
						title:'暂无数据无法导出',
						icon:'none'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.fixed_Export {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
}
</style>